package com.smarthospital.web.controller;

import com.alibaba.fastjson.JSON;
import com.smarthospital.common.Result.ResultDTO;
import com.smarthospital.entity.pojo.MedicalCard;
import com.smarthospital.service.MedicalCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * create by sym  2020/8/16 16:00.
 */
@RestController
@Slf4j
@RequestMapping("/medical")
@Api(tags = "就诊卡")
public class MedicalCardController {

    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    MedicalCardService medicalCardService;

    @PostMapping("/check")
    @ApiOperation(value = "是否注册健康卡  \n " +
            "只需要传hospitalCode参数，可以为空 为空的话为非扫码进入，已经注册过即选择最新的一个，没注册过需要用户选择大医院\n" +
            "返回值  0-未注册  1-已经注册、调用查询【我的健康卡】接口")
    public ResultDTO check(@RequestHeader("SH_TOKEN")String SH_TOKEN,@RequestBody MedicalCard medicalCard) throws Exception {
        log.info("是否注册健康卡 param {}", JSON.toJSONString(medicalCard));
        Integer status = medicalCardService.check(medicalCard);
        return ResultDTO.sucess(status);
    }

    @GetMapping("/queryMine")
    @ApiOperation(value = "查询【我的就诊卡】")
    public ResultDTO queryMine(@RequestHeader("SH_TOKEN")String SH_TOKEN,@RequestParam("hospitalCode")String  hospitalCode) throws Exception {

        MedicalCard medicalCard =  medicalCardService.queryMine(hospitalCode);
        return ResultDTO.sucess(medicalCard);
    }

    /**
     * todo 去医院查询电子健康卡
     * @param SH_TOKEN
     * @param medicalCard
     * @return
     * @throws Exception
     */
    @PostMapping("/register")
    @ApiOperation(value = "注册【我的就诊卡】")
    public ResultDTO register(@RequestHeader("SH_TOKEN")String SH_TOKEN,@RequestBody MedicalCard medicalCard) throws Exception {
        log.info("注册【我的就诊卡】 param {}", JSON.toJSONString(medicalCard));
        medicalCardService.register(medicalCard);
        return ResultDTO.sucess();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改【我的就诊卡】")
    public ResultDTO update(@RequestHeader("SH_TOKEN")String SH_TOKEN,@RequestBody MedicalCard medicalCard) throws Exception {
        log.info("修改【我的就诊卡】 param {}", JSON.toJSONString(medicalCard));
        medicalCardService.update(medicalCard);
        return ResultDTO.sucess();
    }


}
